package cn.bellychang.deferredresult;

import cn.bellychang.CustomUser;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author ChangLiang
 * @date 2020/2/21
 */
@RestController
public class HelloWorldController {

    @GetMapping("/hello")
    public String index() {
        return "hello world";
    }


    @GetMapping("/slow/slowService")
    public Map<String,String> slowService(String username) throws InterruptedException {
        Map<String, String> result = new HashMap<>(1);
        result.put("responseName", username);
        TimeUnit.SECONDS.sleep(2);
        return result;
    }

    @GetMapping("/slow/slowService2")
    public Map<String,Long> slowService2(String token) throws InterruptedException {
        Map<String, Long> result = new HashMap<>(1);
        result.put("userId", 249L);
        TimeUnit.SECONDS.sleep(2);
        return result;
    }

    @GetMapping("/slow/slowService3")
    public CustomUser slowService3(String userId) throws InterruptedException {
        CustomUser user = new CustomUser();
        user.setCustUserId(249L);
        user.setMobile("15311111111");
        user.setCustName("常亮");
        TimeUnit.SECONDS.sleep(2);
        return user;
    }
}
